package org.adorsys.aderp.orga.repository;

import java.util.List;

import org.adorsys.aderp.orga.domain.OrgaPerson;
import org.adorsys.aderp.orga.domain.OrgaRelation;
import org.adorsys.aderp.orga.domain.OrgaRelationRole;
import org.springframework.data.domain.Page;
import org.springframework.data.domain.Pageable;
import org.springframework.roo.addon.layers.repository.jpa.RooJpaRepository;

@RooJpaRepository(domainType = OrgaRelation.class)
public interface OrgaRelationRepository {
	List<OrgaRelation> findByPerson(OrgaPerson person);
	List<OrgaRelation> findByTargetPerson(OrgaPerson targetPerson);

	/**
	 * Person is not null.
	 * 
	 * @param person
	 * @param pageable
	 * @return
	 */
	Page<OrgaRelation> findByPerson(OrgaPerson person, Pageable pageable);
	Page<OrgaRelation> findByPersonAndTargetPerson(OrgaPerson person, OrgaPerson targetPerson, Pageable pageable);
	Page<OrgaRelation> findByPersonAndTargetPersonAndRelationRole(OrgaPerson person, 
			OrgaPerson targetPerson, OrgaRelationRole relationRole, Pageable pageable);

	/**
	 * Person is null and target person is not null
	 * @param targetPerson
	 * @param pageable
	 * @return
	 */
	Page<OrgaRelation> findByTargetPerson(OrgaPerson targetPerson, Pageable pageable);
	Page<OrgaRelation> findByTargetPersonAndRelationRole(
			OrgaPerson targetPerson, OrgaRelationRole relationRole, Pageable pageable);
	
	Page<OrgaRelation> findByRelationRole(OrgaRelationRole relationRole, Pageable pageable);
}
